// -------------------------------------------------
// BlinKit - BlinKit Library
// -------------------------------------------------
//   File Name: qjs_text.cpp
// Description: Bindings for CharacterData
//      Author: Ziming Li
//     Created: 2022-04-01
// -------------------------------------------------
// Copyright (C) 2022 MingYang Software Technology.
// -------------------------------------------------

#include "./qjs_bindings.h"

#include "blinkit/blink/renderer/bindings/core/qjs/qjs.h"
#include "blinkit/blink/renderer/bindings/core/qjs/qjs_c_function_list_entries.h"
#include "blinkit/blink/renderer/core/dom/CharacterData.h"

/**
 * https://developer.mozilla.org/en-US/docs/Web/API/CharacterData
 */

namespace BlinKit {
namespace qjs {

static JSValue GetData(JSContext *ctx, JSValueConst thisVal)
{
    CharacterData *data = ScriptWrappable::Cast<CharacterData>(thisVal);
    return WrapString(ctx, data->data());
}

static JSValue SetData(JSContext *ctx, JSValueConst thisVal, JSValueConst textContent)
{
    ASSERT(false); // BKTODO:
    return JS_UNDEFINED;
}

JSValue CreateCharacterDataPrototype(JSContext *ctx, JSValue nodePrototype)
{
    static const JSCFunctionListEntry Funcs[] = {
        CGetSetEntry(Strings::Data, GetData, SetData),
    };

    JSValue ret = JS_NewObjectProto(ctx, nodePrototype);
    JS_SetPropertyFunctionList(ctx, ret, Funcs, std::size(Funcs));
    return ret;
}

} // namespace qjs
} // namespace BlinKit
